package com.vip8.recorder.service.web.controller;

import com.vip8.recorder.api.facade.DeviceManageFacade;
import com.vip8.recorder.api.model.base.MultiResult;
import com.vip8.recorder.api.model.base.SingleResult;
import com.vip8.recorder.api.model.dto.DeviceLogDTO;
import com.vip8.recorder.api.model.params.ApkParam;
import com.vip8.recorder.api.model.params.DeviceParams;
import com.vip8.recorder.service.service.DeviceManageService;
import com.vip8.recorder.service.utils.JsonUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/deviceManage")
@Validated
@Slf4j
public class DeviceManageController  {
    @Resource
    private DeviceManageService deviceManageService;

    @RequestMapping(value = "/updateApkPatch", method = RequestMethod.POST)
    @ResponseBody
    @Validated
    SingleResult<Boolean> updateApkPatch(@RequestParam String appInfo, @RequestPart MultipartFile apk){
        ApkParam params = JsonUtil.parseObject(appInfo, ApkParam.class);
        Boolean result  = deviceManageService.updateApkPatch(params, apk);
        return SingleResult.success(result);
    }

    @RequestMapping(value = "/updateAppLogFile", method = RequestMethod.POST)
    @ResponseBody
    @Validated
    SingleResult<Boolean> updateAppLogFile(@RequestParam String appInfo, @RequestPart MultipartFile file){
        ApkParam params = JsonUtil.parseObject(appInfo, ApkParam.class);
        Boolean result  = deviceManageService.updateAppLogFile(params, file);
        return SingleResult.success(result);
    }

    @RequestMapping(value = "/queryAppLogFile", method = RequestMethod.POST)
    @ResponseBody
    @Validated
    MultiResult<DeviceLogDTO> queryAppLogFile(@RequestBody String appInfo){
        ApkParam params = JsonUtil.parseObject(appInfo, ApkParam.class);
        List<DeviceLogDTO>  deviceLogDTOS = deviceManageService.queryAppLogFile(params);
        return MultiResult.success(deviceLogDTOS);
    }
}
